const LhzxHttpClient = require('./LhzxHttpClient');

// HTTP请求测试
async function testHttpRequest() {
    console.log('=== HTTP请求功能测试 ===\n');
    
    const client = new LhzxHttpClient();
    
    // 模拟配置
    const mockConfig = {
        user: "testUser",
        siid: "TEST001", 
        secretKey: "testSecretKey123",
        mobile: "13800138000",
        content: "【测试】这是一条测试短信",
    };
    
    // 生成请求参数
    const timeStamp = client.formatTimestamp();
    const transactionID = timeStamp;
    const streamingNo = mockConfig.siid + transactionID;
    const authenticator = client.encoderByMd5(timeStamp + transactionID + streamingNo + mockConfig.secretKey);
    
    const requestData = {
        siid: mockConfig.siid,
        user: mockConfig.user,
        streamingNo: streamingNo,
        timeStamp: timeStamp,
        transactionID: transactionID,
        authenticator: authenticator,
        mobile: mockConfig.mobile,
        content: mockConfig.content
    };
    
    console.log('准备发送的请求数据:');
    console.log(JSON.stringify(requestData, null, 2));
    console.log();
    
    try {
        console.log('正在发送HTTP POST请求到测试服务器...');
        const response = await client.sendPostRequest(
            JSON.stringify(requestData),
            "https://httpbin.org/post"
        );
        
        console.log('HTTP请求成功！');
        console.log('响应内容:');
        
        // 解析JSON响应
        const responseObj = JSON.parse(response);
        console.log('请求头:', responseObj.headers);
        console.log('接收到的数据:', responseObj.json);
        console.log('请求URL:', responseObj.url);
        console.log('请求方法:', responseObj.method);
        
    } catch (error) {
        console.error('HTTP请求失败:', error.message);
        console.error('详细错误:', error);
    }
}

// 运行HTTP测试
testHttpRequest(); 